<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="业务系统订单号" prop="businessId">
        <el-input
          v-model="queryParams.businessId"
          placeholder="请输入业务系统订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="消费者账户ID" prop="consumerAccountId">
        <el-input
          v-model="queryParams.consumerAccountId"
          placeholder="请输入消费者账户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="consumerId">
        <el-input
          v-model="queryParams.consumerId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信用户id" prop="openid">
        <el-input
          v-model="queryParams.openid"
          placeholder="请输入微信用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phoneNum">
        <el-input
          v-model="queryParams.phoneNum"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外部系统的订单号" prop="transactionId">
        <el-input
          v-model="queryParams.transactionId"
          placeholder="请输入外部系统的订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原始业务id" prop="originalBusinessId">
        <el-input
          v-model="queryParams.originalBusinessId"
          placeholder="请输入原始业务id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-input
          v-model="queryParams.payTime"
          placeholder="请输入支付时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总金额(以分为单位)" prop="moneyTotal">
        <el-input
          v-model="queryParams.moneyTotal"
          placeholder="请输入总金额(以分为单位)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="赠送金额" prop="presentedMoney">
        <el-input
          v-model="queryParams.presentedMoney"
          placeholder="请输入赠送金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否可以分账(0 不可分账 1 可分账 2分账中 3分账完结)" prop="profitSharing">
        <el-input
          v-model="queryParams.profitSharing"
          placeholder="请输入是否可以分账(0 不可分账 1 可分账 2分账中 3分账完结)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户号" prop="mercCode">
        <el-input
          v-model="queryParams.mercCode"
          placeholder="请输入商户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据版本" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入数据版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:paylog:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:paylog:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:paylog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:paylog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="paylogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="支付流水id" align="center" prop="payId" />
      <el-table-column label="业务系统订单号" width="160" align="center" prop="businessId" />
      <el-table-column label="消费者账户ID" align="center" prop="consumerAccountId" />
      <el-table-column label="用户ID" align="center" prop="consumerId" />
      <el-table-column label="微信用户id" align="center" prop="openid" />
      <el-table-column label="手机号" align="center" prop="phoneNum" />
      <el-table-column label="外部系统的订单号" align="center" prop="transactionId" />
      <el-table-column label="原始业务id" align="center" prop="originalBusinessId" />
      <el-table-column label="支付时间" align="center" prop="payTime" />
      <el-table-column label="总金额(以分为单位)" align="center" prop="moneyTotal" />
      <el-table-column label="赠送金额" align="center" prop="presentedMoney" />
      <el-table-column label="订单类型 (0 开电订单 1 充值订单 2 地锁订单 3 系统充值 4 退款)" align="center" prop="orderType" />
      <el-table-column label="状态(0:创建  1:成功  2:处理中  3:失败 )" align="center" prop="status" />
      <el-table-column label="是否可以分账(0 不可分账 1 可分账 2分账中 3分账完结)" align="center" prop="profitSharing" />
      <el-table-column label="商户类型(PARTNER 服务商 DIRECT 直连)" align="center" prop="mercType" />
      <el-table-column label="商户号" align="center" prop="mercCode" />
      <el-table-column label="数据版本" align="center" prop="version" />
      <el-table-column label="支付类型(balance wxPay subPay smf card qmf)" align="center" prop="payType" />
      <el-table-column label="描述" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:paylog:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:paylog:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改新支付记录信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="业务系统订单号" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入业务系统订单号" />
        </el-form-item>
        <el-form-item label="消费者账户ID" prop="consumerAccountId">
          <el-input v-model="form.consumerAccountId" placeholder="请输入消费者账户ID" />
        </el-form-item>
        <el-form-item label="用户ID" prop="consumerId">
          <el-input v-model="form.consumerId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="微信用户id" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入微信用户id" />
        </el-form-item>
        <el-form-item label="手机号" prop="phoneNum">
          <el-input v-model="form.phoneNum" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="外部系统的订单号" prop="transactionId">
          <el-input v-model="form.transactionId" placeholder="请输入外部系统的订单号" />
        </el-form-item>
        <el-form-item label="原始业务id" prop="originalBusinessId">
          <el-input v-model="form.originalBusinessId" placeholder="请输入原始业务id" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-input v-model="form.payTime" placeholder="请输入支付时间" />
        </el-form-item>
        <el-form-item label="总金额(以分为单位)" prop="moneyTotal">
          <el-input v-model="form.moneyTotal" placeholder="请输入总金额(以分为单位)" />
        </el-form-item>
        <el-form-item label="赠送金额" prop="presentedMoney">
          <el-input v-model="form.presentedMoney" placeholder="请输入赠送金额" />
        </el-form-item>
        <el-form-item label="是否可以分账(0 不可分账 1 可分账 2分账中 3分账完结)" prop="profitSharing">
          <el-input v-model="form.profitSharing" placeholder="请输入是否可以分账(0 不可分账 1 可分账 2分账中 3分账完结)" />
        </el-form-item>
        <el-form-item label="商户号" prop="mercCode">
          <el-input v-model="form.mercCode" placeholder="请输入商户号" />
        </el-form-item>
        <el-form-item label="数据版本" prop="version">
          <el-input v-model="form.version" placeholder="请输入数据版本" />
        </el-form-item>
        <el-form-item label="描述" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入描述" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPaylog, getPaylog, delPaylog, addPaylog, updatePaylog } from "@/api/business/paylog";

export default {
  name: "Paylog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 新支付记录信息表格数据
      paylogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        consumerAccountId: null,
        consumerId: null,
        openid: null,
        phoneNum: null,
        transactionId: null,
        originalBusinessId: null,
        payTime: null,
        moneyTotal: null,
        presentedMoney: null,
        orderType: null,
        status: null,
        profitSharing: null,
        mercType: null,
        mercCode: null,
        version: null,
        payType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        businessId: [
          { required: true, message: "业务系统订单号不能为空", trigger: "blur" }
        ],
        consumerAccountId: [
          { required: true, message: "消费者账户ID不能为空", trigger: "blur" }
        ],
        consumerId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        openid: [
          { required: true, message: "微信用户id不能为空", trigger: "blur" }
        ],
        phoneNum: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        moneyTotal: [
          { required: true, message: "总金额(以分为单位)不能为空", trigger: "blur" }
        ],
        orderType: [
          { required: true, message: "订单类型 (0 开电订单 1 充值订单 2 地锁订单 3 系统充值 4 退款)不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "状态(0:创建  1:成功  2:处理中  3:失败 )不能为空", trigger: "change" }
        ],
        payType: [
          { required: true, message: "支付类型(balance wxPay subPay smf card qmf)不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询新支付记录信息列表 */
    getList() {
      this.loading = true;
      listPaylog(this.queryParams).then(response => {
        this.paylogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        payId: null,
        businessId: null,
        consumerAccountId: null,
        consumerId: null,
        openid: null,
        phoneNum: null,
        transactionId: null,
        originalBusinessId: null,
        createTime: null,
        payTime: null,
        moneyTotal: null,
        presentedMoney: null,
        orderType: null,
        status: null,
        profitSharing: null,
        mercType: null,
        mercCode: null,
        version: null,
        payType: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.payId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加新支付记录信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const payId = row.payId || this.ids
      getPaylog(payId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改新支付记录信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.payId != null) {
            updatePaylog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPaylog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const payIds = row.payId || this.ids;
      this.$modal.confirm('是否确认删除新支付记录信息编号为"' + payIds + '"的数据项？').then(function() {
        return delPaylog(payIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/paylog/export', {
        ...this.queryParams
      }, `paylog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
